import "crvpuppet"

define at3_ganglia_srv($webaddr="", $roleid="") {
  if $AutoMode==true and $CloudCRV==true {
#    $clientlist=get_dependent_attrlist($webaddr,$roleid,"GangliaClientAddr")
  }
  
  if ( $AutoMode == false ) or ( $AutoMode==true and $CloudCRV==true ) {

    package { ["ganglia", "ganglia-web", "ganglia-gmetad","httpd","ganglia-gmond"]:
      ensure => installed,
    }

    file { "/etc/gmetad.conf":
      owner => "root",
      group => "root",
      mode => 644,
      content => template("at3_ganglia_srv/etc-gmetad.conf.tpl"),
      notify => Service["gmetad"],
    }

    file { "/etc/gmond.conf":
      owner => "root",
      group => "root",
      mode => 644,
      content => template("at3_ganglia_srv/etc-gmond.conf.tpl"),
      notify => Service["gmond"],
    }

    service { ["gmetad", "httpd", "gmond"]:
      ensure => running,
      enable => true,
      hasstatus => true,
      hasrestart => true,
      require => [Package ["httpd", "ganglia", "ganglia-web", "ganglia-gmetad", "ganglia-gmond"],File["/etc/gmetad.conf"], File["/etc/gmond.conf"]],
    }
  }

  if $AutoMode==true and $CloudCRV==true {
    set_role_attr($webaddr,$roleid,"GangliaSrvAddr","$ipaddress")
    #set_role_attr($webaddr,$roleid,"ProfileApplied","True")
  }
}

define at3_ganglia_srv_reverse($webaddr, $roleid) {
  #set_role_attr($webaddr,$roleid,"ReverseProfileApplied","True")
}

